<?php
/**
 * Manuscript Comparator
 * Copyright (C) 2009  OpenScriptures.org
 * $Id: reference-parser-test.php 159 2009-02-25 18:07:31Z WestonRuter@gmail.com $
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

require_once('reference-parser.lib.php');
require_once('svn.lib.php');

?><!DOCTYPE html><!-- HTML5 -->
<html>
	<head>
		<title>Reference Parser Test</title>
		<style>
		input {
			font-size:16px;
			margin-right:5px;
		}
		section:not(.defaultValue) {
			color:gray;
		}
		button.stateChanged {
			font-weight:bold;
		}
		output {
			margin-left:5px;
			font-family:monospace;
			font-size:18px;
		}
		.error {
			color:red;
		}
		footer address,
		footer address + p {
			display:inline;
		}
		footer p {
			margin:0;
		}
		</style>
	</head>
	<body>
		<h1>Reference Parsing Test</h1>
	
		<p>Entering conventional references (New Testament currently) should result in an osisRef:</p>
	
		<?php
		if(!isset($_REQUEST['passage']))
			$_REQUEST['passage'] = "Rom. 5:5-8";
		?>
	
		<form method="get" action="reference-parser-test.php">
			<p><input name='passage' value="<?php echo htmlspecialchars($_REQUEST['passage']) ?>" ?> &rarr; <output></output></p>
			<p><button type="submit">Parse with PHP</button></p>
		</form>
	
		<fieldset id='php-output' class='defaultValue'>
			<legend>PHP Output</legend>
			<p><code>parse_reference("<?php echo htmlspecialchars(addslashes($_REQUEST['passage'])) ?>") == </code><?php
			$osisref = parse_reference($_REQUEST['passage']);
			if($osisref){
				echo '<output>';
				echo htmlspecialchars($osisref);
				echo '</output>';
			}
			else {
				echo '<output class="error">(parse error)</output>';
			}
			?></p>
		
			<?php if($osisref): ?>
				<p><code>format_osisref("<?php echo htmlspecialchars(addslashes($osisref)) ?>") == </code><?php
				$formatted = format_osisref($osisref);
				if($osisref){
					echo '<output>';
					echo htmlspecialchars($formatted);
					echo '</output>';
				}
				else {
					echo '<output class="error">(parse error)</output>';
				}
				?></p>
			<?php endif; ?>
		</fieldset>
	
	
		<p>JavaScript source: <a href="http://code.google.com/p/open-scriptures/source/browse/trunk/web/prototypes/reference-parser.js">&hellip;/trunk/web/prototypes/reference-parser.js</a></p>
		<p>PHP source: <a href="http://code.google.com/p/open-scriptures/source/browse/trunk/web/prototypes/reference-parser.lib.php">&hellip;/trunk/web/prototypes/reference-parser.lib.php</a></p>
	
		<hr />
		<footer>
			<address>
				Copyright 2009, <a href="http://openscriptures.org/" rel="home">OpenScriptures.org</a>. 
			</address>
			<p>Code open source under <a href="http://www.gnu.org/licenses/gpl.html" rel="license">GPL 3</a>.</p>
			<p class='repo'><?php print format_svn_id('$Id: reference-parser-test.php 159 2009-02-25 18:07:31Z WestonRuter@gmail.com $', '$URL: http://open-scriptures.googlecode.com/svn/branches/php-prototypes/reference-parser-test.php $'); ?></p>
		</footer>
		
		<?php if(file_exists('jquery.min.js')): ?>
		<script src="jquery.min.js?ver=1.3.2"></script>
		<?php else: ?>
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
		<?php endif; ?>
		<script src="reference-parser.js?<?php echo filemtime('reference-parser.js') ?>"></script>
		<script>
		$('input:first').keyup(function(e){
			var osisref = parseReference(this.value);
			if(!osisref && this.value)
				$('output:first').addClass('error').text('parse error');
			else
				$('output:first').removeClass('error').text(osisref);
		}).keyup().focus().change(function(){
			$('#php-output').removeClass('defaultValue');
			$('button').addClass('stateChanged');
		});
		</script>
	
		<!-- Google Analytics -->
		<script src="http://www.google-analytics.com/ga.js"></script>
		<script type="text/javascript">
		try {
			var pageTracker = _gat._getTracker("UA-6816157-1");
			pageTracker._trackPageview();
		} catch(e) {}
		</script>
	</body>
</html>
